package com.hntky.controller;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hntky.common.Result;
import com.hntky.entity.Doctor;
import com.hntky.service.DoctorService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.print.Doc;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.List;

@RestController
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService service;

    @GetMapping("/")
    public Result index() {
        return Result.success(service.list());
    }

    /**
     * 分页查询与搜索
     * @param pageNum
     * @param pageSize
     * @param dname
     * @return
     */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String dname) {
        return Result.success(service.findPage(new Page<>(pageNum, pageSize), dname));

    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del/batch")
    public Result delBatch(@RequestBody List<Integer> ids) {
        return Result.success(service.removeBatchByIds(ids));
    }


    /**
     * 新增与修改
     * @param doctor
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody Doctor doctor) {
        return Result.success(service.saveOrUpdate(doctor));
    }

    /**
     * 根据id删除
     * @param did
     * @return
     */
    @GetMapping("/{did}")
    public Result del(@PathVariable Integer did) {
        return Result.success(service.removeById(did));
    }

    /**
     * 查看病人信息
     * @param did
     * @return
     */
    @GetMapping("/patient/{did}")
    public Result findPatients(@PathVariable Integer did){
        return Result.success(service.findPatients(did));
    }

}
